[id].vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. <template>
  2. <div id="newsList">
  3. <!-- 页面头部 -->
  4. <HomePageHead></HomePageHead>
  5. <!-- Banner1 -->
  6. <HomeBanner1></HomeBanner1>
  7. <!-- 面包屑导航 -->
  8. <div class="breadcrumb">
  9. <div class="inner">
  10. <span class="location">当前位置:</span>
  11. <el-breadcrumb :separator-icon="ArrowRight">
  12. <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
  13. <el-breadcrumb-item :to="{ path: '/newsList' }">{{ name }}</el-breadcrumb-item>
  14. </el-breadcrumb>
  15. </div>
  16. </div>
  17. <!-- 资讯列表 -->
  18. <div class="newsList">
  19. <div class="inner">
  20. <div class="innerLeft">
  21. <ul class="list">
  22. <li v-for="(item, index) in newsList" :key="index">
  23. <NuxtLink :to="`/newsDetail/${item.id}`" target="_blank">{{ item.title }}</NuxtLink>
  24. </li>
  25. </ul>
  26. <!-- 分页器 -->
  27. <div class="pagination">
  28. <el-pagination size="small" background layout="prev, pager, next" :total="total" class="mt-4"
  29. prev-text="上一页" next-text="下一页" @change="changePage" />
  30. <!-- <HomePagination @sendData="handleData"></HomePagination> -->
  31. </div>
  32. </div>
  33. <div class="innerRight">
  34. <DetailHotNews></DetailHotNews>
  35. </div>
  36. </div>
  37. </div>
  38. <!-- 三农资讯logo -->
  39. <HomeSannongzixun></HomeSannongzixun>
  40. <!-- 资讯推荐 -->
  41. <div class="zixuntuijian">
  42. <div class="inner">
  43. <div class="innerLeft">
  44. <div class="zixunLeft">
  45. <!-- 标题部分 -->
  46. <div class="title">
  47. <h3>
  48. 资讯推荐
  49. <!-- <span>查看更多</span> -->
  50. </h3>
  51. </div>
  52. <!-- 图片和文字列表 -->
  53. <ul class="photo_text">
  54. <li v-for="item in news1">
  55. <img :src="item.imgurl" alt="">
  56. <div>
  57. <h5>{{ item.title }}</h5>
  58. <p>
  59. <span>{{ item.author }}</span>
  60. <span>{{ item.created_at }}</span>
  61. </p>
  62. </div>
  63. </li>
  64. <li v-for="item in news11">
  65. <em></em>
  66. {{ item.title }}
  67. </li>
  68. </ul>
  69. </div>
  70. <div class="zixunRight">
  71. <!-- 标题部分 -->
  72. <div class="title">
  73. <h3>
  74. 资讯推荐
  75. <!-- <span>查看更多</span> -->
  76. </h3>
  77. </div>
  78. <!-- 图片和文字列表 -->
  79. <ul class="photo_text">
  80. <li v-for="item in news2">
  81. <img :src="item.imgurl" alt="">
  82. <div>
  83. <h5>{{ item.title }}</h5>
  84. <p>
  85. <span>{{ item.author }}</span>
  86. <span>{{ item.created_at }}</span>
  87. </p>
  88. </div>
  89. </li>
  90. <li v-for="item in news22">
  91. <em></em>
  92. {{ item.title }}
  93. </li>
  94. </ul>
  95. </div>
  96. </div>
  97. <div class="innerRight">
  98. <!-- 标题部分 -->
  99. <div class="title">
  100. <h4>
  101. 热点资讯
  102. <!-- <span>查看更多</span> -->
  103. </h4>
  104. </div>
  105. <!-- 列表 -->
  106. <ul class="rightList">
  107. <li v-for="item in hotlistall">
  108. <img class="left" :src="item.imgurl">
  109. <p class="left">{{ item.title }}</p>
  110. </li>
  111. </ul>
  112. </div>
  113. </div>
  114. </div>
  115. <!-- 页面底部 -->
  116. <HomeFoot></HomeFoot>
  117. </div>
  118. </template>
  119. <script setup>
  120. import { onMounted } from 'vue';
  121. import { ElBreadcrumb, ElBreadcrumbItem, ElPagination } from 'element-plus'
  122. import { ArrowRight } from '@element-plus/icons-vue'
  123. const nuxtApp = useNuxtApp();
  124. const axios = nuxtApp.$axios;
  125. //获得跳转过来的id
  126. const route = useRoute();
  127. const articleId = route.params.id; //获得该页面的id
  128. // const category_id = route.query.category_id; //获得该页面的id
  129. const category_id = route.query.catid; //获得该页面的id
  130. const name = route.query.name; //获得该页面的id
  131. console.log(name);
  132. // 定义响应式数据
  133. const seoData = ref({
  134. title: '默认标题',
  135. description: '默认描述',
  136. keywords: '默认关键词',
  137. image: 'https://example.com/default-image.jpg'
  138. });
  139. // 在 onMounted 钩子中获取数据
  140. onMounted(async () => {
  141. try {
  142. const response = await axios.get("`/web/getWebsiteCategoryHead?catid=${articleId}`");
  143. const data = response.data.website_head; // 假设接口返回的数据在 data 字段中
  144. console.log(seoData.value.title)
  145. // 更新 seoData
  146. seoData.value = {
  147. title: data.seo_title,
  148. description: data.seo_description,
  149. keywords: data.seo_keywords,
  150. image: data.seo_image
  151. };
  152. console.log(seoData.value.title)
  153. } catch (error) {
  154. console.error('获取 SEO 数据失败:', error);
  155. // 设置默认值
  156. seoData.value = {
  157. title: '默认标题',
  158. description: '默认描述',
  159. keywords: '默认关键词',
  160. image: 'https://example.com/default-image.jpg'
  161. };
  162. }
  163. });
  164. // 监听 seoData 的变化,动态设置 SEO 字段
  165. watch(seoData, (newVal) => {
  166. if (newVal.title) { // 确保 title 有值
  167. useSeoMeta({
  168. title: newVal.title, // 使用动态值
  169. description: newVal.description,
  170. ogTitle: newVal.title,
  171. ogDescription: newVal.description,
  172. ogImage: newVal.image,
  173. twitterTitle: newVal.title,
  174. twitterDescription: newVal.description,
  175. twitterImage: newVal.image,
  176. keywords: newVal.keywords
  177. });
  178. }
  179. }, { immediate: true });
  180. //关键词
  181. let keyWord = useState("keyWord", () => "")
  182. let id = useState("id", () => "")
  183. let total = useState("total", () => 0)
  184. let page = useState("page", () => 1)
  185. let pageSize = useState("pageSize", () => 10)
  186. onMounted(() => {
  187. id.value = route.query.id;
  188. console.log('id', id.value);
  189. })
  190. // 页码
  191. // //页面组件传递数据的时间驱动函数
  192. // const handleData = (data) => {
  193. // console.log(data.value)
  194. // page.value = data.value
  195. // //在页码发生变化时去请求响应页面的新闻数据
  196. // axios.get(`/web/getWebsiteArticleList?page=${page.value}&pageSize=${10}&catid=${14}&keyword=${keyWord.value}`).then(response => {
  197. // // console.log(response.data.rows);
  198. // newsList.value = response.data.rows;
  199. // }).catch(error => {
  200. // console.error(error);
  201. // })
  202. // }
  203. let changePage = (value) => {
  204. console.log("当前页码", value);
  205. page.value = value
  206. console.log(page.value);
  207. newslists()
  208. }
  209. // 一级导航
  210. const navigation1 = ref("");
  211. const navigateList = async () => {
  212. try {
  213. const response = await axios.get(`/web/getWebsiteModelCategory?placeid=${1}&pid=${0}&num=${24}`);
  214. console.log('一级导航', response.data);
  215. navigation1.value = response.data;
  216. console.log('111111111111111111111111111', navigation1[0]?.value.category_id);
  217. } catch (error) {
  218. console.error(error);
  219. }
  220. }
  221. // 新闻列表
  222. const newsList = useState("newsList", () => '');
  223. const newslists = async () => {
  224. try {
  225. const response = await axios.get(`/web/getWebsiteArticleList?page=${page.value}&pageSize=${pageSize.value}&catid=${category_id}`);
  226. // console.log(response.data.rows);
  227. newsList.value = response.data.rows;
  228. total.value = response.data.count;
  229. } catch (error) {
  230. console.error(error);
  231. }
  232. }
  233. //热点资讯
  234. const hotlistall = useState("hotlistall", () => "");
  235. const hotlist = async () => {
  236. try {
  237. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${2}&level=${4}&placeid=${1}`);
  238. console.log('热点资讯', response.data);
  239. for (let item of response.data) {
  240. console.log(item);
  241. item.count = 1;
  242. }
  243. hotlistall.value = response.data;
  244. } catch (error) {
  245. console.error(error);
  246. }
  247. }
  248. //资讯推荐1
  249. const news1 = useState("news1", () => "");
  250. const newslist1 = async () => {
  251. try {
  252. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${1}&level=${5}&placeid=${1}`);
  253. console.log('热点资讯', response.data);
  254. news1.value = response.data;
  255. } catch (error) {
  256. console.error(error);
  257. }
  258. }
  259. const news11 = useState("news11", () => "");
  260. const newslist11 = async () => {
  261. try {
  262. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${3}&level=${5}&placeid=${1}`);
  263. console.log('热点资讯', response.data);
  264. news11.value = response.data;
  265. } catch (error) {
  266. console.error(error);
  267. }
  268. }
  269. //资讯推荐2
  270. const news2 = useState("news2", () => "");
  271. const newslist2 = async () => {
  272. try {
  273. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${1}&level=${5}&placeid=${1}`);
  274. console.log('热点资讯', response.data);
  275. news2.value = response.data;
  276. } catch (error) {
  277. console.error(error);
  278. }
  279. }
  280. const news22 = useState("news22", () => "");
  281. const newslist22 = async () => {
  282. try {
  283. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${3}&level=${5}&placeid=${1}`);
  284. console.log('热点资讯', response.data);
  285. news22.value = response.data;
  286. } catch (error) {
  287. console.error(error);
  288. }
  289. }
  290. //挂载成功钩子函数
  291. onMounted(() => {
  292. // 资讯推荐
  293. newslists()
  294. // 热点资讯
  295. hotlist()
  296. // 资讯推荐
  297. newslist1()
  298. newslist2()
  299. // 热点资讯
  300. newslist11()
  301. newslist22()
  302. navigateList()
  303. })
  304. //路由中间件
  305. definePageMeta({
  306. middleware: 'auth'
  307. })
  308. </script>
  309. <style lang="less" scoped>
  310. //导航条
  311. .breadcrumb {
  312. width: 100%;
  313. height: 22px;
  314. margin-bottom: 30px;
  315. font-family: Microsoft YaHei, Microsoft YaHei;
  316. font-weight: 400;
  317. font-size: 20px;
  318. color: #666666;
  319. line-height: 23px;
  320. text-align: left;
  321. font-style: normal;
  322. text-transform: none;
  323. :deep(.el-breadcrumb) {
  324. display: inline-block;
  325. vertical-align: -4px;
  326. }
  327. :deep(.el-breadcrumb__inner a),
  328. :deep(.el-breadcrumb__inner.is-link) {
  329. color: #666666;
  330. font-weight: 400;
  331. text-decoration: none;
  332. transition: var(--el-transition-color);
  333. }
  334. span {
  335. font-family: Microsoft YaHei, Microsoft YaHei;
  336. font-weight: 400;
  337. font-size: 20px;
  338. color: #666666;
  339. line-height: 23px;
  340. text-align: left;
  341. font-style: normal;
  342. text-transform: none;
  343. }
  344. span:hover {
  345. color: #666666;
  346. }
  347. .location {
  348. margin-right: 20px;
  349. width: 100px;
  350. height: 22px;
  351. font-family: Microsoft YaHei, Microsoft YaHei;
  352. font-weight: 400;
  353. font-size: 20px;
  354. color: #666666;
  355. line-height: 23px;
  356. text-align: left;
  357. font-style: normal;
  358. text-transform: none;
  359. }
  360. }
  361. // 资讯列表
  362. .newsList {
  363. width: 100%;
  364. height: 675px;
  365. margin-bottom: 70px;
  366. .inner {
  367. width: 1200px;
  368. .innerLeft,
  369. .innerRight {
  370. border-top: 1px solid #139602;
  371. }
  372. .innerLeft {
  373. height: 675px;
  374. >.list {
  375. height: 570px;
  376. margin-bottom: 70px;
  377. >li {
  378. width: 790px;
  379. height: 56px;
  380. white-space: nowrap;
  381. overflow: hidden;
  382. text-overflow: ellipsis;
  383. line-height: 56px;
  384. border-bottom: 1px solid #D9D9D9;
  385. >a {
  386. width: 360px;
  387. height: 26px;
  388. font-family: Microsoft YaHei, Microsoft YaHei;
  389. font-weight: 400;
  390. font-size: 20px;
  391. color: #333333;
  392. line-height: 26px;
  393. text-align: left;
  394. font-style: normal;
  395. text-transform: none;
  396. }
  397. }
  398. >li:hover>a {
  399. color: #139602;
  400. }
  401. >li:nth-child(1)::after,
  402. >li:nth-child(2)::after {
  403. content: "热";
  404. margin-left: 13px;
  405. background: #FF8A37;
  406. color: #fff;
  407. font-size: 14px;
  408. padding: 0px 2px;
  409. }
  410. }
  411. >.pagination {
  412. width: 800px;
  413. height: 34px;
  414. margin-left: 141px;
  415. display: flex;
  416. justify-content: center;
  417. margin: 0;
  418. // 鼠标移入后字体颜色
  419. .el-pagination::v-deep :hover {
  420. color: #139609;
  421. }
  422. .el-pagination.is-background::v-deep .btn-next,
  423. .el-pagination.is-background::v-deep .btn-prev {
  424. width: 70px;
  425. height: 34px;
  426. margin: 0px 10px;
  427. border-radius: 4px;
  428. }
  429. .el-pagination.is-background::v-deep .el-pager li {
  430. margin: 0px 10px;
  431. width: 38px;
  432. height: 34px;
  433. border-radius: 4px;
  434. }
  435. .el-pagination.is-background::v-deep .btn-next.is-active,
  436. .el-pagination.is-background::v-deep .btn-prev.is-active,
  437. .el-pagination.is-background::v-deep .el-pager li.is-active {
  438. background-color: #028e21;
  439. color: #fff;
  440. }
  441. }
  442. }
  443. .innerRight {
  444. width: 381px;
  445. height: 605px;
  446. }
  447. }
  448. }
  449. //资讯推荐
  450. .zixuntuijian {
  451. width: 100%;
  452. height: 290px;
  453. margin-bottom: 70px;
  454. .innerLeft {
  455. // 左侧
  456. .zixunLeft {
  457. margin-right: 30px;
  458. }
  459. .zixunRight,
  460. .zixunLeft {
  461. float: left;
  462. width: 380px;
  463. height: 290px;
  464. // 标题部分
  465. >.title {
  466. width: 380px;
  467. }
  468. >.title>h3 {
  469. height: 36px;
  470. font-family: Source Han Sans, Source Han Sans;
  471. font-weight: bold;
  472. font-size: 24px;
  473. color: #000000;
  474. line-height: 28px;
  475. text-align: left;
  476. font-style: normal;
  477. text-transform: none;
  478. border-bottom: 1px solid #139602;
  479. }
  480. >.title>h3>span {
  481. float: right;
  482. width: 56px;
  483. height: 20px;
  484. line-height: 24px;
  485. font-weight: 400;
  486. font-size: 14px;
  487. color: #999999;
  488. font-style: normal;
  489. text-transform: none;
  490. }
  491. .photo_text {
  492. >li:first-child {
  493. width: 380px;
  494. height: 120px;
  495. margin-top: 20px;
  496. margin-bottom: 15px;
  497. position: relative;
  498. >img {
  499. float: left;
  500. width: 160px;
  501. height: 120px;
  502. }
  503. >div {
  504. float: left;
  505. width: 220px;
  506. height: 120px;
  507. padding-left: 15px;
  508. padding-top: 6px;
  509. box-sizing: border-box;
  510. background-color: #f6f6f6;
  511. >h5 {
  512. width: 200px;
  513. height: 54px;
  514. display: -webkit-box;
  515. -webkit-box-orient: vertical;
  516. -webkit-line-clamp: 2;
  517. overflow: hidden;
  518. text-overflow: ellipsis;
  519. word-break: break-all;
  520. font-family: Source Han Sans, Source Han Sans;
  521. font-weight: 500;
  522. font-size: 18px;
  523. color: #333333;
  524. line-height: 26px;
  525. text-align: left;
  526. font-style: normal;
  527. text-transform: none;
  528. }
  529. >p {
  530. width: 200px;
  531. height: 22px;
  532. line-height: 20px;
  533. position: absolute;
  534. bottom: 5px;
  535. right: 0;
  536. >span {
  537. display: inline-block;
  538. // width: 100px;
  539. height: 18px;
  540. font-family: Source Han Sans, Source Han Sans;
  541. font-weight: 400;
  542. font-size: 12px;
  543. color: #999999;
  544. text-align: left;
  545. line-height: 14px;
  546. font-style: normal;
  547. text-transform: none;
  548. }
  549. >span:last-child {
  550. // width: 90px;
  551. text-align: right;
  552. margin-left: 20px;
  553. }
  554. }
  555. }
  556. }
  557. >li {
  558. width: 380px;
  559. height: 25px;
  560. white-space: nowrap;
  561. overflow: hidden;
  562. text-overflow: ellipsis;
  563. font-family: PingFang SC, PingFang SC;
  564. font-weight: 500;
  565. font-size: 18px;
  566. color: #333333;
  567. line-height: 21px;
  568. text-align: left;
  569. font-style: normal;
  570. text-transform: none;
  571. margin-bottom: 10px;
  572. em {
  573. display: inline-block;
  574. width: 8px;
  575. height: 8px;
  576. border-radius: 8px;
  577. margin-right: 10px;
  578. background-color: #d9d9d9;
  579. }
  580. }
  581. >li:hover {
  582. color: #139602;
  583. }
  584. >li:hover em {
  585. background-color: #139602;
  586. }
  587. }
  588. }
  589. }
  590. .innerRight {
  591. width: 381px;
  592. height: 290px;
  593. background-color: #fbfbfb;
  594. >.title {
  595. width: 380px;
  596. height: 40px;
  597. line-height: 40px;
  598. border-top: 1px solid #139602;
  599. border-bottom: 1px solid #e7e7e7;
  600. >h4 {
  601. font-family: Microsoft YaHei, Microsoft YaHei;
  602. font-weight: 400;
  603. margin-left: 20px;
  604. font-size: 20px;
  605. color: #000000;
  606. text-align: left;
  607. font-style: normal;
  608. text-transform: none;
  609. >span {
  610. float: right;
  611. font-family: Microsoft YaHei, Microsoft YaHei;
  612. font-weight: 400;
  613. font-size: 14px;
  614. margin-right: 10px;
  615. color: #999999;
  616. text-align: left;
  617. font-style: normal;
  618. text-transform: none;
  619. }
  620. }
  621. }
  622. .rightList {
  623. height: 540px;
  624. margin-top: 20px;
  625. >li {
  626. height: 100px;
  627. margin-bottom: 10px;
  628. >img {
  629. width: 150px;
  630. height: 100px;
  631. }
  632. >p {
  633. width: 219px;
  634. height: 100px;
  635. padding-left: 12px;
  636. font-family: PingFang SC, PingFang SC;
  637. font-weight: 400;
  638. font-size: 16px;
  639. color: #333333;
  640. line-height: 22px;
  641. text-align: left;
  642. font-style: normal;
  643. text-transform: none;
  644. }
  645. >p:hover {
  646. box-shadow: 0 0 16px 1px rgba(0, 0, 0, 0.1);
  647. }
  648. }
  649. }
  650. }
  651. }
  652. </style>